package study.springcloud.hystrix.client;

import cn.hutool.core.thread.ThreadUtil;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class UserClient {

    @HystrixCommand
    public UserInfo getUserInfo(long timeout) {
        log.info("1111111111");
        ThreadUtil.sleep(timeout, TimeUnit.SECONDS);
        log.info("22222222222222");
        return new UserInfo();
    }

//    @HystrixCommand(fallbackMethod = "getUserInfoByFallback")
    public UserInfo getUserInfo2() {
        if (1 == 1) {
            throw new RuntimeException("防守打法");
        }
        return new UserInfo();
    }

    public UserInfo getUserInfoByFallback() {
        log.info("saaaaaaaaaaaaaaaaaaaa");
        return new UserInfo();
    }
}
